﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;


namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class ODailyReport_GetMachineTaskTime4_GroupBySerialNumberHighcharts : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "ODailyReport";
            }
        }
        #region 属性 (查询条件)
        protected int screeWidth
        {
            get
            {
                var x = GetRequestValue<int>("screeWidth", 800);
                return x - 80;
            }
        }

        protected string WorkDateForm
        {
            get
            {
                return GetRequestValue<string>("WorkDateForm", DateTime.Now.ToString("yyyy-MM-01"));

            }
        }

        protected string WorkDateTo
        {
            get
            {
                return GetRequestValue<string>("WorkDateTo", DateTime.Now.ToString("yyyy-MM-dd"));
            }
        }

        protected string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");
            }
        }

        protected string ReportTitle
        {
            get
            {
                return string.Format("项目{0}各工位所耗工时", SerialNumber);
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethond", "") != "")
            {

                Response.Write(GetGongWeiWorkTime());
                Response.End();
                return;
            }
            DataBind4();
        }

        protected void DataBind4()
        {

            DataTable dt = ODailyController.GetMachineTaskTime4_GroupBySerialNumber(SerialNumber);
            rpMachineTaskTimeChart4.DataSource = dt;
            rpMachineTaskTimeChart4.DataBind();
            rpMachineTaskTimeChart4Show.DataSource = dt;
            rpMachineTaskTimeChart4Show.DataBind();   
            
        }

        protected string GetGongWeiWorkTime()
        {
            string GongWei = GetRequestValue<string>("GongWei", "");
            string hours = GetRequestValue<string>("hours", "");
            DataTable dt = ODailyController.GetMachineTaskTime4_GroupByGongWei(SerialNumber);

            DataRow[] drs= dt.Select(string.Format(" GongWei='{0}'", GongWei));
            string resultHtml = "<b>[{1}]{0}</b><br/>所耗总工时:{2}小时<br/>---------------<br/>{3}";
            string htmlstr2 = "";
            foreach (DataRow dr in drs)
            {
                htmlstr2 += string.Format("<b>{0}</b>:{1}小时<br/>", dr["realname"], Convert.ToDecimal( dr["TaskTime"]).ToString("f2"));
            }

            return string.Format(resultHtml, GongWei,IHISCETeimDict.GetGongWeiValue(GongWei), hours, htmlstr2);
        }
    }
}